<!DOCTYPE html>
<html>
<!--
author:guojunyu
date:2019-05
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="/static/css/login_reglogin.css"/>
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
        <title>安全设置</title>
</head>
<body>
	<div class="bg">
		<img src="/static/images/b.jpg" alt="">
	</div>
	<div class="main">
		<div class="header" >
			<h1>密码更改</h1>
		</div>
		<p></p>
			<ul class="right-form">
				<h2>安全设置-密码更改</h2>
				<li><input type="text" id='old_password' class="password"    placeholder="原密码" required/></li>
				<li><input type="password" id='password_1' class="password"  placeholder="新密码" required/></li>
				<li><input type="password" id='password_2' class="password"  placeholder="再次输入新密码" required/></li>
				<input type="button" value="修改密码" onclick="cpassword()">
				<div class="clear"> </div>
			</ul>
			<div class="clear"> </div>
	</div>
	
</body>

    <script>
        function cpassword(){
        var old_password = $('#old_password').val();
        var password_1 = $('#password_1').val();
        var password_2 = $('#password_2').val();
        var post_data = {"old_password":old_password, "password_1":password_1,"password_2":password_2 };;
        var token = window.localStorage.getItem('token');
    	var username = window.localStorage.getItem('username');


        $.ajax({
        // 请求方式
        type:"put",
        // contentType 
        contentType:"application/json",
        // dataType
        dataType:"json",

        // url
        url:"http://127.0.0.1:8000/v1/users/" + username + "/password",
        // 把JS的对象或数组序列化一个json 字符串
        data:JSON.stringify(post_data),
        // result 为请求的返回结果对象
		beforeSend: function(request) {
            request.setRequestHeader("Authorization", token);
        },
        success:function (result) {
            if (result.code == 200){
                alert('修改成功, 请重新登录');
                window.localStorage.removeItem('token');
                window.localStorage.removeItem('username');
                window.location.href = '/login'
            }else{
                alert(result.error)
            }
        }
    });

    }
    </script>

</html>
